package com.tinshow.config.utils.http.v42;

import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.scheme.SchemeSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;

public abstract class HttpsClient extends DefaultHttpClient {

    protected SchemeSocketFactory schemeSocketFactory;

    /**
     * 初始化httpsclient
     * @return
     * @throws Exception
     */
    public HttpsClient init() throws Exception {
        this.prepareCertificate();
        return this;
    }

    /**
     * 准备证书验证
     * @throws Exception
     */
    public abstract void prepareCertificate() throws Exception;

    /**
     * 注册协议和端口
     */
    protected void regist() {
        ClientConnectionManager ccm = this.getConnectionManager();
        SchemeRegistry spr = ccm.getSchemeRegistry();
        spr.register(new Scheme("https", 443, this.schemeSocketFactory));
    }
}
